/**
 * @file geminai_sdklink_connect.h
 * @brief 根据后台规则生成获取设备密钥，连接阿里云客户端
 * @author zl
 */

#ifndef __GEMINAI_SDKLINK_CONNECT__
#define __GEMINAI_SDKLINK_CONNECT__

#include "mbedtls/sha256.h"
#include "mbedtls/md5.h"
#include "esp_tls.h"
#include "esp_http_client.h"
#include "esp_log.h"
#include "geminai_log.h"
#include "cJSON.h"

#include "aiot_state_api.h"
#include "aiot_sysdep_api.h"
#include "aiot_mqtt_api.h"

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "esp_err.h"

#include "freertos/event_groups.h"
#include "esp_system.h"
#include "esp_event.h"

#include "lwip/err.h"
#include "lwip/sys.h"

#include <unistd.h>

#include <sys/param.h>
#include <ctype.h>
#include "esp_crt_bundle.h"
#include "esp_netif.h"
#include <time.h>
#include "esp_sntp.h"
#include "esp_netif_sntp.h"
#include "geminai_mqtt_cache.h"
#include "geminai_para.h"
#include "geminai_gpio.h"

#include "esp_ota_ops.h"
#include "geminai_modbus.h"

#include "aiot_ota_api.h"
#include "aiot_mqtt_download_api.h"

#define MBEDTLS_MD5_32_SIZE 33
#define MBEDTLS_SHA256_64_SIZE 65

#define MAX_HTTP_RECV_BUFFER 512
#define MAX_HTTP_OUTPUT_BUFFER 1024

// 定义一个内存块的结构体，包含数据指针和大小
typedef struct {
    void *data;
    size_t size;
} MemoryBlock;

/* 位于portfiles/aiot_port文件夹下的系统适配函数集合 */
extern aiot_sysdep_portfile_t g_aiot_sysdep_portfile;

/* 位于external/ali_ca_cert.c中的服务器证书 */
extern const char *ali_ca_cert;

extern void *mqtt_handle;




//url获取设备密钥
void http_rest_with_url(const char *s_url, const char *secret, const char *name, char *d_secret,  char *asset_id,  char *url , char *product_key);

//连接阿里云客户端
int linkkit_start(const char *s_url, const char *key, const char *name, char *d_secret);

//断开连接
int linkkit_stop(void);

void task_connect_aliyun(void *args);
void mqtt_task_start(void);

#endif